import { getUrlParams,personName } from './utils';

let seekHelpDataSource = [];

for (let i = 0; i < 50; i += 1) {
  seekHelpDataSource.push({
    id: i,
    avatar: ['https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png', 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png'][i % 2],
    name: personName[Math.floor(Math.random()*100)+i],
  });
}

export function getFans(req, res, u) {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== '[object String]') {
    url = req.url; // eslint-disable-line
  }

  const params = getUrlParams(url);

  let dataSource = [...seekHelpDataSource];

  //查询翻译内容关键字
  if (params.seekHelpTitle) {
    dataSource = dataSource.filter(data => data.seekHelpTitle.indexOf(params.seekHelpTitle) > -1);
  }

  let pageSize = 10;
  if (params.pageSize) {
    pageSize = params.pageSize * 1;
  }

  const result = {
    list: dataSource,
    pagination: {
      total: dataSource.length,
      pageSize,
      current: parseInt(params.currentPage, 10) || 1,
    },
  };

  if (res && res.json) {
    res.json(result);
  } else {
    return result;
  }
}


export default {
  getFans,
};
